package cn.ml.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class MyDate {
    public static void main(String[] args) {
        //设置日期格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();

        String startDate = "2012-03-24";
        String endDate = "2021-10-16";
        try {
            //将字符串转换为Date格式
            Date begin = sdf.parse(startDate);
            Date end = sdf.parse(endDate);
            //比较日期大小
            if (begin.before(end)){
                c.setTime(begin);
                c.add(Calendar.DATE,1);//添加一天后日期
                begin = c.getTime();//得到Date格式
                System.out.println("得到Date格式："+begin);
                startDate = sdf.format(begin);
                System.out.println("得到字符串格式："+startDate);


            }

        } catch (ParseException e) {
            e.printStackTrace();
        }


    }
}
